<?php

require_once 'command/Command.php';
require_once 'database/DatabaseConnection.php';
require_once 'database/Product.php';

class GetProductCommand implements Command {
	
	private $id;
	private $product;
	
	public function __construct($id){
		$this->id = $id;
		$this->product = new Product(); 
	}
	
	
	public function execute(){
		$string = "<product>";
		DatabaseConnection::connect();
		$arrayObj = $this->product->getProduct($this->id);
		DatabaseConnection::disconnect();
		$it = $arrayObj->getIterator();
		while($it->valid()){
			$arr = $it->current();
			$string .= 	"<id>".$arr['id']."</id>";
			$string .= 	"<name>".$arr['name']."</name>";
			$string .= 	"<price>".$arr['price']."</price>";
			$string .= 	"<tag>".$arr['tag']."</tag>";
			break;
		}
		$string .= "</product>";
		return $string;
	}
}